package Vue;

import javax.swing.JDialog;
import java.awt.Point;
import java.awt.Dimension;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.Color;
import java.util.ArrayList;

import Controleur.LoadSource;
import Controleur.SuppClientBtnListener;
import Controleur.SuppClientComboListener;

/**
 * Définit la fenetre de suppression d'un client
 *
 */
public class SupprimerClient extends JDialog {

	/** Liste déroulant des clients */
	final JComboBox comboBoxClient;
	/** Bouton validant la suppression */
	final JButton btnValider = new JButton("Valider");
	private static final long serialVersionUID = 1L;
	/** Label indiquant si le client loue un vélo */
	private final JLabel lblClientLoueAct = new JLabel(
			"Le client loue actuellement un v\u00E9lo");
	
	/**
	 * Instancie la fenetre de suppression
	 */
	public SupprimerClient() {
		setModal(true);
		setResizable(false);
		setMinimumSize(new Dimension(300, 300));
		setLocation(new Point(200, 200));

		JPanel panel = new JPanel();
		getContentPane().add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		JLabel lblSupprimerUnClient = new JLabel("Supprimer un client");
		lblSupprimerUnClient.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblSupprimerUnClient.setBounds(72, 23, 164, 20);
		panel.add(lblSupprimerUnClient);


		ArrayList<Object> clients = LoadSource.getClients();
		comboBoxClient = new JComboBox(clients.toArray());
		comboBoxClient.setToolTipText("Selectionner un client");
		comboBoxClient.setBounds(86, 88, 133, 20);
		panel.add(comboBoxClient);

		btnValider.setEnabled(false);

		btnValider.setFont(new Font("Tahoma", Font.BOLD, 12));
		btnValider.setForeground(new Color(0, 128, 0));
		btnValider.setBounds(110, 174, 89, 23);
		panel.add(btnValider);
		lblClientLoueAct.setVisible(false);
		lblClientLoueAct.setBounds(72, 137, 164, 14);

		panel.add(lblClientLoueAct);

		// Listeners
		comboBoxClient.addActionListener(new SuppClientComboListener(this));
		btnValider.addActionListener(new SuppClientBtnListener(this));

		// On selectionne la première ligne
		if (comboBoxClient.getItemCount() != 0)
			comboBoxClient.setSelectedIndex(0);

	}

	
	// Getters
	/**
	 * Getter du champ Client
	 * @return ComboBoxClient
	 */
	public JComboBox getComboBoxClient() {
		return comboBoxClient;
	}
	/**
	 * Getter du bouton valider
	 * @return	btnValider
	 */
	public JButton getBtnValider() {
		return btnValider;
	}
	/**
	 * Getter du label indiquant si le client loue actuellement
	 * @return lblClientLoueAct
	 */
	public JLabel getLblClientLoueAct() {
		return lblClientLoueAct;
	}

	/**
	 * Méthode fermant la fenetre
	 */
	public void close() {
		this.dispose();
	}
}
